import java.io.IOException;

import cz.dhl.ftp.Ftp;
import cz.dhl.ftp.FtpConnect;
import cz.dhl.ftp.FtpFile;
import cz.dhl.io.CoFile;
import cz.dhl.io.CoLoad;
import cz.dhl.io.LocalFile;


public class PruebaDescargaModis {

	public static void main(String[] args) {
		FtpConnect cn = FtpConnect.newConnect("ftp://e4ftl01.cr.usgs.gov/MOLT/MOD09Q1.005/2010.05.25/");
		Ftp cl = new Ftp();
		try {
			cn.setPassWord("IEUser@");
			cl.connect(cn);
			
			CoFile dir = new  FtpFile(cl.pwd(), cl);
			// hacer una lista de archivos que tiene el directoria actual
			CoFile fls[] = dir.listCoFiles();
			if ( fls != null )
				for (int n = 0; n < fls.length; n++)
					System.out.println( fls[n].getName() + (fls[n].isDirectory() ? "/" : ""));
			
		    /* source FtpFile remote file */
		    CoFile file = new FtpFile("/Rossi_De Angelis_31-03-10_rev 0.ppt",cl);

		    /* destination LocalFile home-dir/Welcome */
		    CoFile to = new LocalFile(System.getProperty("user.dir"),file.getName());

		    /* download /Welcome file to home-dir/Welcome */
		    CoLoad.copy(to,file);
			
		} catch (IOException e) {
			e.printStackTrace();
		} finally { /* disconnect from server 
   	  				 * this must be always run */
			cl.disconnect();
		}


	}

}
